/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sisfo.astacala.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

/**
 *
 * @author arif
 */
public class InterceptorGeneral implements Interceptor {

    @Override
    public void destroy() {
        System.out.println("destroy");
    }

    @Override
    public void init() {
        System.out.println("init");
    }

    @Override
    public String intercept(ActionInvocation ai) {
        String result = "";
        try {
//        System.out.println("=== user session : " + ai.getInvocationContext().getSession().get("user"));
            if (ai.getInvocationContext().getSession().get("user") == null) {
                result = "error";
            } else {
                result = ai.invoke();
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            result = "error";
        }
        return result;
    }
}
